package LeetCodeSection;/*
 *
 *@author:    Xavier
 *@data:      2023 - 08 - 20
 *@time:      14:36
 *
 */


import java.util.Stack;

//13. 二叉树中序非递归遍历实现
//https://leetcode.cn/problems/binary-tree-inorder-traversal/
public class BinaryTreeInorder {
    public static void InOrderNor(TreeNode root) {
        if (root == null) return;
        Stack<TreeNode> stack = new Stack<>();
        TreeNode cur = root;

        while (cur != null || !stack.empty()) {
            while (cur != null) {
                stack.push(cur);
                cur = cur.left;
            }
            //cur == null  此时cur的左边走完 要判断右边
            TreeNode top = stack.pop();
            System.out.print(top.val + " ");
            cur = top.right;
        }
    }
}
